package life.majiang.community.dto;

import life.majiang.community.exception.CoutomizeErrorCode;
import life.majiang.community.exception.CustomizeException;
import lombok.Data;

@Data
public class ResultDTO<T> {
    private Integer code;
    private String  message;
    private T data;

    public static ResultDTO erroeOf(Integer code, String message){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(code);
        resultDTO.setMessage(message);
        return resultDTO;
    }

    public static ResultDTO erroeOf(CoutomizeErrorCode errorCode) {

        return erroeOf(errorCode.getCode(),errorCode.getMessage());
    }


    public static ResultDTO okOf(){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(200);
        resultDTO.setMessage("请求成功");
        return resultDTO;
    }

    public static <T>ResultDTO okOf( T t){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(200);
        resultDTO.setMessage("请求成功");
        resultDTO.setData(t);
        return resultDTO;
    }


    public static ResultDTO erroeOf( CustomizeException e) {
        return erroeOf(e.getCode(),e.getMessage());
    }


}
